extends InspectableItem

var state:State = null
var history:PackedStringArray = ["", ""]
var rule:Rule = null

func _ready() -> void:
	rule = RuleStandard.new()

func set_state(_state:State) -> void:
	state = _state.duplicate()

func push_move(move:int) -> void:
	history.push_back(rule.get_move_name(state, move))
	rule.apply_move(state, move, state.add_piece, state.capture_piece, state.move_piece, state.set_extra, state.push_history, state.change_score)
	update_table()

func update_table() -> void:
	$sub_viewport/rich_text_label.text = "[table=3]"
	for i:int in range(history.size()):
		if i % 2 == 0:
			$sub_viewport/rich_text_label.text += "[cell]%d[/cell]" % (i / 2)
		$sub_viewport/rich_text_label.text += "[cell]%s[/cell]" % history[i]

func add_blank_line() -> void:
	history.push_back("")
	history.push_back("")
